#ifndef DYNAMICXUCS_H
#define DYNAMICXUCS_H

#include <QStyleOption>
#include <QPainter>
#include <QMouseEvent>

#include "adaptivewidgets.h"


enum class DynamicX
{
    NoiseGate,
    Compressor,
    Limiter
};

// 噪声门，压缩器，限制器
class DynamicXUCS : public AWidget
{
    Q_OBJECT
public:
    enum RectSelected
    {
        NotSelected,
        ThresholdSelected,
        RatioSelected
    };
    Q_ENUM(RectSelected)
    explicit DynamicXUCS(const DynamicX &type, const double &maxThreshold, QWidget *parent = nullptr);

signals:
    void thresholdChanged(double);
    void ratioChanged(int);
public slots:
    void setThreshold(const double &threshold);
    void setRatio(const uint8_t &ratio);
protected:
    void paintEvent(QPaintEvent *event) override;

    void mousePressEvent(QMouseEvent *event) override;

    void mouseMoveEvent(QMouseEvent *event) override;

    void mouseReleaseEvent(QMouseEvent *event) override;
private:
    double toThreshold(const QPointF &point) const;
    uint8_t toRatio(const QPointF &point) const;
private:
    const DynamicX m_type;
    double m_maxThreshold;
    QRectF m_cRect;
    QRectF m_rectThreshold;
    QRectF m_rectRatio;
    double m_threshold;
    uint8_t m_ratio;
    RectSelected m_selected = NotSelected;
};

#endif // DYNAMICXUCS_H
